package com.taomu.app.zongchouhuli.moudle.mine.activity;

import android.app.Dialog;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.taomu.app.zongchouhuli.R;
import com.taomu.app.zongchouhuli.entity.BaseFinishEntity;
import com.taomu.app.zongchouhuli.framework.BaseActivity;
import com.taomu.app.zongchouhuli.framework.BasePresenter;
import com.taomu.app.zongchouhuli.utils.RxBus2;

public class UserRechargeResultsActivity extends BaseActivity {

    protected ImageView mBackIm;

    private TextView mBackOrderTv;

    @Override
    protected int getContentLayout() {
        return R.layout.activity_recharge_results;
    }

    @Override
    protected void initView() {
        mBackIm = findViewById(R.id.recharge_results_back_im);
        mBackOrderTv = findViewById(R.id.back_home);
    }

    @Override
    protected void initData() {
        if(getIntent() != null){
            boolean isrecharege = getIntent().getBooleanExtra("isrecharege", false);
            if(isrecharege){
                showdialog();
            }
        }
    }

    @Override
    protected void initEvent() {
        mBackIm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finishSelf();
            }
        });
        mBackOrderTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finishSelf();
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK){
            finishSelf();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    private void finishSelf(){
        RxBus2.getInstance().post(new BaseFinishEntity());
        UserOrderActivity.start(UserRechargeResultsActivity.this, 2);
        finish();
    }

    private void showdialog(){
        View view = LayoutInflater.from(this).inflate(R.layout.dialog_recharge_layout, null);
        final Dialog dialog = new Dialog(this,R.style.RecharegeDialogStyle);
        dialog.setContentView(view);
        final TextView mBackTv = view.findViewById(R.id.again_back_tv);
        mBackTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finishSelf();
            }
        });
        final TextView mAgainTv = view.findViewById(R.id.again_recharge_tv);
        mAgainTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RxBus2.getInstance().post(new BaseFinishEntity());
                startActivity(UserRechargeActivity.class);
                finish();
            }
        });
        final ImageView mClose = view.findViewById(R.id.close_im);
        mClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(dialog != null){
                    dialog.dismiss();
                }
            }
        });
        dialog.show();
    }
}
